//
//  commentCell.m
//  YouGoWeGo
//
//  Created by 范业君 on 14-11-27.
//  Copyright (c) 2014年 LiuFei. All rights reserved.
//

#import "commentCell.h"
#import "commentModel.h"
#import "UIImageView+WebCache.h"

@implementation commentCell


- (void)dealloc
{
    [_cHead release];
    [_nameLabel release];
    [_commInfor release];
    [_reply release];
    [self removeObserver:self forKeyPath:@"comModel"];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.cHead = [[UIImageView alloc] initWithFrame:CGRectZero];
        //[_cHead setBackgroundColor:[UIColor redColor]];
        [_cHead.layer setCornerRadius:17.5];
        [_cHead setClipsToBounds:YES];
        [self.contentView addSubview:_cHead];
        [_cHead release];
        
        self.nameLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        //[_nameLabel setBackgroundColor:[UIColor redColor]];
        [self.contentView addSubview:_nameLabel];
        [_nameLabel release];
        
        self.commInfor = [[UILabel alloc] initWithFrame:CGRectZero];
        //[_commInfor setBackgroundColor:[UIColor redColor]];
        [self.contentView addSubview:_commInfor];
        [_commInfor release];
        
        self.reply = [[UIButton alloc] initWithFrame:CGRectZero];
        //[_reply setBackgroundColor:[UIColor redColor]];
        [_reply setTitle:@"回复" forState:UIControlStateNormal];
        [_reply.titleLabel setFont:[UIFont systemFontOfSize:10]];
        [self.contentView addSubview:_reply];
        [_reply setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        [_reply release];
        
        [self addObserver:self forKeyPath:@"comModel" options:NSKeyValueObservingOptionNew context:nil];
        
    }
    return self;
}


- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if ([keyPath isEqualToString:@"comModel"]) {
        [self.cHead setImageWithURL:[self.comModel.user objectForKey:@"avatar_m"]];
        [self.nameLabel setText:[self.comModel.user objectForKey:@"name"]];
        [self.commInfor setText:self.comModel.comment];
        
    }
}



- (void)layoutSubviews
{
    [super layoutSubviews];
    [_cHead setFrame:CGRectMake(15, 10, 35, 35)];
    
    [_nameLabel setFrame:CGRectMake(_cHead.frame.origin.x + _cHead.frame.size.width + 5, _cHead.frame.origin.y - 5, 70, 25)];
    [_nameLabel setFont:[UIFont systemFontOfSize:10]];
    [_commInfor setFrame:CGRectMake(_nameLabel.frame.origin.x + _nameLabel.frame.size.width + 5, _nameLabel.frame.origin.y, 150,25)];
    [_commInfor setFont:[UIFont systemFontOfSize:11]];
    [_reply setFrame:CGRectMake(self.frame.size.width - 40, _nameLabel.frame.size.height, 30, 20)];
    
}








- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
